#include "cubicItem.h"
#include "data.h"
#include <QLabel>
#include <QString>
#include <QColor>
#include <QPalette>
#include <qmath.h>

cubicItem :: cubicItem()
{
    this->resize(64,64);
    this->setMinimumSize(64,64);
    //this->setMaximumSize(64,64);
    this->setAlignment(Qt::AlignCenter);
    this->setText("");
    this->setStyleSheet("border:0px;border-style:solid;border-color:rgb(0,0,0);");
    this->setAutoFillBackground(true);
    //this->setStyleSheet("background-color:#ff0000;");
   // QColor color(125,130,130);
 /*   QColor red(255,0,0,255);
    QPalette *p = new QPalette;
    p->setColor(QPalette::Background,red);
    this->setPalette(*p);*/
    //this->show();

    connect(this,SIGNAL(value_changed(int)),this,SLOT(slot_change_color(int)));
}
cubicItem::~cubicItem()
{}
void cubicItem::set_value(int value)
{
    if (QString::number(value) != (this->text()))
        emit value_changed(value);
    if (value == 0)
        this->setText("");
    else
        this->setNum(value);
}
void cubicItem::slot_change_color(int value)
{
    int tmp = (log2N(value) - 1) * 10;
    int red = (((125 + tmp) <= 255) ? (125 + tmp) : 255);
    int blue = ((130 - tmp) >= 0) ? (130 - tmp) : 0;
    int green = ((130 - tmp) >= 0) ? (130 - tmp) : 0;
    this->setStyleSheet(QString("background-color:rgb(%1,%2,%3)").arg(red).arg(blue).arg(green));
}
